package com.example.dnfgamercommunitybackend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfiguration{
    @Bean
    public RedisTemplate<String,Object> redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String,Object> template = new RedisTemplate<>();
        //配置连接工厂
        template.setConnectionFactory(redisConnectionFactory);
        //key序列化方式
        template.setKeySerializer(new StringRedisSerializer());
        //value序列化方式
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //hashKey序列化方式
        template.setHashKeySerializer(new StringRedisSerializer());
        //hashValue序列化方式
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
